package com.itheima.service.mongo.impl;

import com.itheima.domain.mongo.Sound;
import com.itheima.service.mongo.SoundService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@DubboService
public class SoundServiceImpl implements SoundService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void publishSound(Sound sound) {
        //把音频保存到mongoDb中
        mongoTemplate.save(sound);
    }

    @Override
    public Sound findSound(Long userId) {


        Sound sound = mongoTemplate.findOne(new Query(Criteria.where("userId").ne(userId)), Sound.class);
        return sound;

    }
}
